package com.webull.information.center.carwler.dao;

import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import com.webull.information.center.carwler.common.model.SpeclNewsPlan;
import com.webull.information.center.dao.JdbcHelper;

@Repository
public class SpeclNewsPlanDao {
	private static final RowMapper<SpeclNewsPlan> speclPlanRM = BeanPropertyRowMapper
			.newInstance(SpeclNewsPlan.class);
	protected final Logger logger = LogManager.getLogger(getClass());

	private @Autowired JdbcTemplate jdbcTemplate;

	private @Autowired NamedParameterJdbcTemplate namedParameterJdbcTemplate;

	/**
	 * 
	 * @param lastId
	 * @return
	 */
	public List<SpeclNewsPlan> queryPaging(Integer lastId) {
		return jdbcTemplate.query(Sql.pagingQuery, new Object[] { lastId }, speclPlanRM);
	}

	public void update(SpeclNewsPlan plan) {
		namedParameterJdbcTemplate.update(Sql.updateById, JdbcHelper.getSqlParameterSource(plan));
	}
	private static class Sql {
		private static final String pagingQuery = "select * from wli_specl_news_plan where id > ? and del = 0 order by id asc limit 100";
		private static final String updateById = "update wli_specl_news_plan  set exec_stat=ifnull(:execStat,exec_stat),exec_time=ifnull(:execTime,exec_time),next_time=ifnull(:nextTime,next_time),exec_count=(exec_count+ ifnull(:execCount,0)) where id = :id";
	}
}

